package com.gitee.melin.bee.core.jdbc.dialect.impl;

import com.gitee.melin.bee.core.jdbc.dialect.AbstractJdbcDialect;
import com.gitee.melin.bee.core.jdbc.enums.DataSourceType;
import com.gitee.melin.bee.core.jdbc.relational.BeeTableType;
import com.gitee.melin.bee.core.jdbc.relational.ConnectionInfo;
import java.sql.Connection;
import java.sql.Driver;

/** https://github.com/IBM/trino-db2 */
public class DB2JdbcDialect extends AbstractJdbcDialect {

    @Override
    public DataSourceType getDataSourceType() {
        return DataSourceType.DB2;
    }

    public DB2JdbcDialect(ConnectionInfo connectionInfo) {
        super(connectionInfo);
    }

    public DB2JdbcDialect(Connection connection) {
        super(connection);
    }

    @Override
    protected Driver getDriver() {
        return loadDriver(DataSourceType.DB2.getDriverClass());
    }

    @Override
    protected String getSelectTablesSql(String tableName) {
        return "SELECT OWNER,TABNAME NAME,TABSCHEMA,REMARKS,CREATE_TIME,ALTER_TIME,AVGROWSIZE * CARD DATA_LENGTH,CARD \"\n"
                + "                + \"FROM  SYSCAT.TABLES WHERE OWNER = :schemaName  AND TYPE ='T'";
    }

    @Override
    protected String getSelectColumnsSql() {
        return "SELECT * FROM SYSCAT.COLUMNS WHERE TABSCHEMA = :schemaName AND TABNAME = :tableName ORDER BY COLNO WITH UR";
    }

    @Override
    protected String getDDLColumnName(BeeTableType type) {
        throw new IllegalArgumentException("未定义 DDLColumnName");
    }
}
